# -*- coding: utf-8 -*-

class VtGateway(object):
	"""交易接口"""

	#----------------------------------------------------------------------
	def __init__(self, eventEngine, gatewayName):
		"""Constructor"""
		self.binding_instance = eventEngine
		self.gatewayName = gatewayName
		
	#----------------------------------------------------------------------
	def onTick(self, tick):
		"""市场行情推送"""
		# 通用事件
		event1 = Event(type_=EVENT_TICK)
		event1.dict_['data'] = tick
		self.binding_instance.put(event1)
		
		# 特定合约代码的事件
		event2 = Event(type_=EVENT_TICK+tick.vtSymbol)
		event2.dict_['data'] = tick
		self.binding_instance.put(event2)
	
	#----------------------------------------------------------------------
	def onTrade(self, trade):
		"""成交信息推送"""
		# 通用事件
		event1 = Event(type_=EVENT_TRADE)
		event1.dict_['data'] = trade
		self.binding_instance.put(event1)
		
		# 特定合约的成交事件
		event2 = Event(type_=EVENT_TRADE+trade.vtSymbol)
		event2.dict_['data'] = trade
		self.binding_instance.put(event2)
	
	#----------------------------------------------------------------------
	def onOrder(self, order):
		"""订单变化推送"""
		# 通用事件
		event1 = Event(type_=EVENT_ORDER)
		event1.dict_['data'] = order
		self.binding_instance.put(event1)
		
		# 特定订单编号的事件
		event2 = Event(type_=EVENT_ORDER+order.vtOrderID)
		event2.dict_['data'] = order
		self.binding_instance.put(event2)
	
	#----------------------------------------------------------------------
	def onPosition(self, position):
		"""持仓信息推送"""
		# 通用事件
		event1 = Event(type_=EVENT_POSITION)
		event1.dict_['data'] = position
		self.binding_instance.put(event1)
		
		# 特定合约代码的事件
		event2 = Event(type_=EVENT_POSITION+position.vtSymbol)
		event2.dict_['data'] = position
		self.binding_instance.put(event2)
	
	#----------------------------------------------------------------------
	def onAccount(self, account):
		"""账户信息推送"""
		# 通用事件
		event1 = Event(type_=EVENT_ACCOUNT)
		event1.dict_['data'] = account
		self.binding_instance.put(event1)
		
		# 特定合约代码的事件
		event2 = Event(type_=EVENT_ACCOUNT+account.vtAccountID)
		event2.dict_['data'] = account
		self.binding_instance.put(event2)
	
	#----------------------------------------------------------------------
	def onError(self, error):
		"""错误信息推送"""
		# 通用事件
		event1 = Event(type_=EVENT_ERROR)
		event1.dict_['data'] = error
		self.binding_instance.put(event1)
		
	#----------------------------------------------------------------------
	def onLog(self, log):
		"""日志推送"""
		# 通用事件
		
		import pydevd
		
		
		event1 = Event(type_=EVENT_LOG)
		event1.dict_['data'] = log
		self.binding_instance.put(event1)
		
	#----------------------------------------------------------------------
	def onContract(self, contract):
		"""合约基础信息推送"""
		# 通用事件
		event1 = Event(type_=EVENT_CONTRACT)
		event1.dict_['data'] = contract
		self.binding_instance.put(event1)
	
	#----------------------------------------------------------------------
	def connect(self):
		"""连接"""
		pass
	
	#----------------------------------------------------------------------
	def subscribe(self, subscribeReq):
		"""订阅行情"""
		pass
	
	#----------------------------------------------------------------------
	def sendOrder(self, orderReq):
		"""发单"""
		pass
	
	#----------------------------------------------------------------------
	def cancelOrder(self, cancelOrderReq):
		"""撤单"""
		pass
	
	#----------------------------------------------------------------------
	def qryAccount(self):
		"""查询账户资金"""
		pass
	
	#----------------------------------------------------------------------
	def qryPosition(self):
		"""查询持仓"""
		pass
	
	#----------------------------------------------------------------------
	def close(self):
		"""关闭"""
		pass


